package behavior.commend;

import java.util.ArrayList;
import java.util.List;

public class RemoteController {
    List<Command> onCommandList = new ArrayList<Command>();
    List<Command> offCommandList = new ArrayList<Command>();
    Command lastCommand = new NoCommand();

    private static final int row = 5;

    RemoteController(){
        for(var i=0;i<row;i++){
            onCommandList.add(new NoCommand());
            offCommandList.add(new NoCommand());
        }
    }

    private boolean checkIndex(int row){
        return row >= 0 && row < RemoteController.row;
    }


    public void setCommand(int row,Command onCommand,Command offCommand) {
        if(checkIndex(row)){
            offCommandList.set(row, offCommand);
            onCommandList.set(row,onCommand);
        }
    }

    public void pressOn(int row){
        if(checkIndex(row)){
            lastCommand = onCommandList.get(row);
            lastCommand.execute();
        }
    }
    public void pressOff(int row){
        if(checkIndex(row)){
            lastCommand = offCommandList.get(row);
            lastCommand.execute();
        }
    }
    public void pressUndo(){
        lastCommand.undo();
    }

}
